<?php

/**
 * Description of ValidateCategory
 *
 * @author welcome
 */
class ValidateCategory extends AbstractValidateFactory implements ICreatePolicyFactory {

    /**
     * Constructor
     * @param type $policy
     */
    public function __construct($policy) {
        $this->policy = $policy;
    }

    /**
     * Create specification
     * @return ISpecification
     */
    private function createPolicyFactory() {
        $field = $this->policy['rules'][0]['field'];
        $value = $this->policy['rules'][0]['value'];
        return $this->isEqual($field, $value);
    }

    /**
     * Validate category template
     * @param type $expenses
     * @return boolean
     */
    public function validate($expenses = array()) {
        $bRet = false;
        if ($this->createPolicyFactory()->isSatistifiedBy($expenses)) {
            $bRet = true;
            $this->message = $this->policy['message'];
        }
        return $bRet;
    }

//put your code here
}
